package org.hpm.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.hpm.common.api.vo.HpmResult;
import org.hpm.common.constant.enums.YesOrNo;
import org.hpm.common.system.base.controller.HpmBaseController;
import org.hpm.entity.HpmCarousel;
import org.hpm.entity.HpmCategory;
import org.hpm.entity.HpmUsers;
import org.hpm.service.IHpmCarouselService;
import org.hpm.service.IHpmCategoryService;
import org.hpm.service.IHpmUsersService;
import org.hpm.vo.HpmCategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页
 *
 * @author: jacklin
 * @since 2022/8/31 11:52
 **/
@Api(value = "首页", tags = {"首页展示的相关接口"})
@RestController
@RequestMapping("/index")
@Slf4j
public class HpmIndexController {

    @Autowired
    private IHpmCarouselService hpmCarouselService;
    @Autowired
    private IHpmCategoryService hpmCategoryService;

    /**
     * 获取首页轮播图列表
     *
     * @author: jacklin
     * @since 2022/8/31 12:00
     **/
    @ApiOperation(value = "获取首页轮播图列表", notes = "获取首页轮播图列表", httpMethod = "GET")
    @GetMapping(value = "/carousels")
    public HpmResult<?> carousels() {
        LambdaQueryWrapper<HpmCarousel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(HpmCarousel::getIsShow, YesOrNo.YES.code);
        List<HpmCarousel> carousels = hpmCarouselService.list(lambdaQueryWrapper);
        return HpmResult.ok(carousels);
    }

    /**
     * 获取商品一级分类列表
     *
     * @author: jacklin
     * @since 2022/9/3 15:09
     **/
    @ApiOperation(value = "获取商品一级分类列表", notes = "获取商品一级分类列表", httpMethod = "GET")
    @GetMapping(value = "/cats")
    public HpmResult<?> cats() {
        List<HpmCategory> categoryList = hpmCategoryService.queryAllRootLevelCategory();
        return HpmResult.ok(categoryList);
    }

    /**
     * 获取商品子分类信息
     *
     * @author: jacklin
     * @since 2022/9/3 15:09
     **/
    @ApiOperation(value = "获取商品子分类信息", notes = "获取商品子分类信息", httpMethod = "GET")
    @GetMapping(value = "/subCat/{rootCatId}")
    public HpmResult<?> subCat(@ApiParam(name = "rootCatId", value = "一级分类id", required = true) @PathVariable(value = "rootCatId") Integer rootCatId) {
        if (rootCatId == null) {
            return HpmResult.errorMsg("分类不存在！");
        }
        List<HpmCategoryVO> categoryVOList = hpmCategoryService.querySubCategoryList(rootCatId);
        return HpmResult.ok(categoryVOList);
    }

}
